package com.ccl.iot.controler;

import android.content.Context;
import android.graphics.drawable.StateListDrawable;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.ccl.iot.device.IOTDevice;
import com.ccl.iot.device.IOTDoor;
import com.ccl.iot.device.IOTSwitch;
import com.ccl.iot.R;

public class GridControlerView extends FrameLayout{
	
	private IOTDevice mDevice;
	private ImageView mIv;
	private StateListDrawable mDrawable;

	public GridControlerView(Context context, IOTDevice aDevice) {
		super(context);
		mDevice = aDevice;
		View.inflate(context, R.layout.grid_item, this);
		mIv = (ImageView) findViewById(R.id.item_img);
		
		mDrawable = new StateListDrawable();
		
	    //Pressed
		mDrawable.addState(new int[]{android.R.attr.state_pressed},
				getResources().getDrawable(R.drawable.icon_curtain_d_stop));
		mDrawable.addState(new int[]{-android.R.attr.state_pressed},
	            getResources().getDrawable(R.drawable.icon_stop_curtain_off));
		
		initUI();
		initListener();
		
	}

	private void initUI() {
		if(mDevice instanceof IOTSwitch){
			isSwitch();
		}else if(mDevice instanceof IOTDoor){
			isDoor();
		}
	}

	private void isDoor() {
		mIv.setImageDrawable(mDrawable);
		mIv.setEnabled(false);
		mIv.setFocusable(false);
	}

	private void isSwitch() {
		
	}
	
	private void initListener() {
		
	}
	
}
